<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Service;

/**
 * Description of User
 *
 * @author dongasai
 */
class User
{

    /**
     * 获取登录信息
     */
    static function info($client_id, $data)
    {
        $uid   = session('uid');
        $where = [
            'uid' => $uid
        ];
        $info  = db('user_info')->where($where)->find();

        if ($info) {
            return \Data\Redata::success("用户信息获取成功", $info, 'User', 'info');
        } else {
            return \Data\Redata::error("用户信息不存在,请先完善", $info, 'User', 'info');
        }
    }

    static function friends($client_id, $data)
    {
        $uid               = session('uid');
        $where             = [
            'uid' => $uid
        ];
        $friends_uid_list  = db('user_friends')->where($where)->column('friends_uid');
        dump($friends_uid_list);
        $friends_uid_list2 = [];
        foreach ($friends_uid_list as $v) {
            $friends_uid_list2[] = $v;
        }
        if (!$friends_uid_list) {
            return \Data\Redata::error("您还没有好友", $friends_uid_list, 'User', 'friends');
        }
        $friends_info_list = db('user_info')->where('uid', 'in', $friends_uid_list)->select();
        dump($friends_info_list);
        if ($friends_info_list) {
            return \Data\Redata::success("用户好友列表获取成功", $friends_info_list, 'User', 'friends');
        } else {
            return \Data\Redata::error("用户好友列表获取失败", $friends_uid_list, 'User', 'friends');
        }
    }

}
